<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Xgo_payment_service{
	var $partnerID = '';
	var $secretKey = '';
	var $wsdl = "http://ws.xgo6.net/ZingMePayment.asmx?wsdl";
	var $cryptKey = "";
	
	var $client = NULL;

	function __construct(){
		$this->client = new SoapClient($this->wsdl);
	}

	function init($para = array()){
		if(!empty($para)){
			foreach($para as $key => $value){
				$this->{$key} = $value;
			}
		}
		$this->client = new SoapClient($this->wsdl);
	}

	function payment_init($username, $user_id, $item_id, $item_name, $item_quantity, $item_price, $amount, $timestamp, $server){	
/* 		echo '<pre>';
		echo 'username: ' . $username . '<br />';
		echo 'item_id: ' . $item_id .  '<br />';
		echo 'user_id: ' . $user_id .  '<br />';
		echo 'item_name: ' . $item_name . '<br />';
		echo 'item_quantity: ' . $item_quantity . '<br />';
		echo 'amount: ' . $amount . '<br />';
		echo 'item_price: ' . $item_price . '<br />';
		echo 'timestamp: ' . $timestamp . '<br />';
		echo 'server: ' . $server . '<br />'; */
		
		//echo 'Signature: ' . md5($this->partnerID.$username.$amount.$server.$this->secretKey) . '<br />';
		
		$result = $this->client->Payment_Init(array(
    			'UserName' => $username,
    			'UserID' => $user_id,
    			'ItemID' => $item_id,
				'ItemName' => $item_name,
				'ItemQuantity' => $item_quantity,
    			'ItemPrice' => $item_price,
				'Amount' => $amount,
				'Timestamp' => $timestamp,
				'ServerName' => $server,
				'PartnerID' => $this->partnerID,
    			'Signature' => md5($this->partnerID.$username.$amount.$server.$this->secretKey)
		));	
		
		return $result->Payment_InitResult;
	}
	
	function payment_commit($result_code, $bill_number, $id_zing_credit, $error_message){
	
		$result = $this->client->Payment_Commit(array(
    			'PartnerID' => $this->partnerID,
    			'ResultCode' => $result_code,
				'BillNoAppGame' => $bill_number,
				'TxIDZingCredits' => $id_zing_credit,
				'ErrorMessage' => $error_message,
    			'Signature' => md5($this->partnerID.$bill_number.$id_zing_credit.$this->secretKey)
		));
	
		return $result->Payment_CommitResult;
	}
}
?>